using Code;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Threading.Tasks;

namespace Models
{
    //[Table("P_Users")]
    public class Users
    {
        //[Key(DatabaseGeneratedAttribute[])]

        [DisplayName("用户ID")]
        public long Id { get; set; }

        /// <summary>
        /// 用户编号，为：年月+当月注册人数，如：18090001
        /// </summary>
        [Column("UserCode", TypeName = "varchar(20)")]
        [DisplayName("会员编号")]
        [List("Show", (int)UserTypes.普通用户)]
        public string UserCode { get; set; }

        [DisplayName("账  号")]
        [List("Show", (int)UserTypes.管理员)]
        public string Account {
            get {
                return UserCode;
            }
        }


        [Required, Column("UserName", TypeName = "varchar(20)")]
        [DisplayName("姓 名")]
        [List("Show", (int)UserTypes.普通用户)]
        public string UserName { get; set; }

        [Column("UserPhone", TypeName = "varchar(18)")]
        [DisplayName("联系手机")]
        [List("Show", (int)UserTypes.普通用户)]
        public string Phone { get; set; }

        [Required, Column("Password", TypeName = "varchar(50)")]
        public string Password { get; set; }

        /// <summary>
        /// 二级密码
        /// </summary>
        [Column("SecondaryPwd", TypeName = "varchar(50)")]
        public string SecondaryPwd { get; set; }

        [Column("CreateTime", TypeName = "datetime")]
        [DisplayName("创建时间")]
        public DateTime CreateTime { get; set; } = DateTime.Now;

        [Column("UserType", TypeName = "smallint")]
        public UserTypes UserType { get; set; } = UserTypes.管理员;

        [Column("LevelCode", TypeName = "smallint")]
        public LevelCode Level { get; set; }

        [DisplayName("用户等级")]
        [List("Show", (int)UserTypes.普通用户)]
        public string strLevel {
            get {
                return Level.ToString();
            }
        }

        [Column("IdCard", TypeName = "varchar(18)")]
        [DisplayName("身份证")]
        [List("Show", (int)UserTypes.普通用户)]
        public string IdCard { get; set; }

        /// <summary>
        /// 推荐人Id
        /// </summary>
        public long ParentId { get; set; } = 0;

        /// <summary>
        /// 市Id，可为0
        /// </summary>
        public int CityId { get; set; } = 0;

        /// <summary>
        /// 省Id
        /// </summary>
        public int ProvinceId { get; set; } = 0;

        [DisplayName("团队人数")]
        public long TeamCount { get; set; } = 1;

        /// <summary>
        /// 余额
        /// </summary>
        [Required, Column("Overage", TypeName = "money")]
        public decimal Overage { get; set; } = 0;

        [DisplayName("余额")]
        [List("Show", 99, Templet = "#aTpl")]
        public string strOverage {
            get {
                return Overage.ToString("C");
            }
        }

        [Required, Column("IsEnable", TypeName = "bit")]
        public bool IsEnable { get; set; } = true;

        public virtual ICollection<CashInfo> Cash { get; set; }

        public virtual ICollection<ShippingAddress> ShippingAddress { get; set; }
    }
}
